<?php
	/** Implementa la traduzione della query tramite URI nella query al database **/
	
	$exp_table = "Pippo";
	$exp_table_workref = "Work";
	$work_table = "Pluto";
	$work_table_id = "ID";

	$w_identifier = "identifier";
	$work_table_identifier = "w_id";

	$w_author = "author";
	$work_table_author = "w_author";
	

	$query = 	"SELECT * ".
			"FROM ".$work_table.", ".$exp_table." ".
			"WHERE (".$exp_table.".".$exp_table_workref."=".$work_table.".".$work_table_id.") ";

	//TODO : Se la query e` vuota NON funziona

	$empty_query = true;
	$error_query = false;
	foreach($_GET as $key => $val)
	{
		switch ($key) {
			case $w_identifier:
    				$query = $query."AND (".$work_table.".".$work_table_identifier."=\"".$val."\") ";
				$empty_query = false;
    				break;
			case $w_author:
    				$query = $query."AND (".$work_table.".".$work_table_author."=\"".$val."\") ";
    				$empty_query = false;
				break;
			default:
				$error_query = true;
				break;
		}
	}

	if ($empty_query) echo "<p>La query e` vuota</p>";
	else if ($error_query) echo "<p>ERRORE</p>";
	else echo "<p>" . $query . "</p>";

?>

<?php
/*
if ($DEBUG) {
	test_print_uri_handler ();
	if (strpos($_SERVER['REQUEST_URI'],'/pw/caio-wip.php')==0) {
		include $SCRIPT_DIR . '/test/caio-wip.php5';
		die();
	}
}
*/
?>